import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[500];
        arr[0] = 0;
        arr[1] = 1;
        for (int i = 2; i < 500; i++) {
            arr[i] = arr[i-1] + arr[i-2];
        }
        long tmp1 = 0;
        long tmp2 = 0;

        if(n > arr[499]) {
            System.out.println(n - arr[499]);
            return;
        }
        for (int  i = 0; i < 500-1; i++) {
            if(n == 1) {
                System.out.println(0);
                break;
            }
            if(n == arr[i]) {
                System.out.println(0);
                break;
            }
           else if(n > arr[i] && n < arr[i+1]) {
                 tmp1 = n - arr[i];
                 tmp2 = arr[i+1] - n;
                 break;
            }
        }
        if(tmp1 > tmp2) {
            System.out.println(tmp2);
        }
        if(tmp2 > tmp1){
            System.out.println(tmp1);
        }
    }
}

